<template>
  <a-modal
    :title="title"
    :width="1000"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row>
          <a-col :span="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="轮播图片">
              <j-image-upload class="avatar-uploader" text="上传图片" v-decorator="[ 'url', validatorRules.url]"></j-image-upload>
            </a-form-item>
          </a-col>


          <a-col :span="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="备注">
              <a-textarea placeholder="请输入备注" v-decorator="['remarks', {}]"/>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import JImageUpload from '@/components/cn-form/JImageUpload'
import {httpAction} from '@/api/manage'
// import JDate from '@/components/cn-form/JDate'
// import {pick} from 'lodash'
import moment from "moment"

export default {
  name: "RotationModal",
  components: {
    // JDate,
    JImageUpload
  },
  data() {
    return {
      title: "操作",
      visible: false,
      orderMainModel: {
        jeecgOrderCustomerList: [{}],
        jeecgOrderTicketList: [{}]
      },
      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {
        url:{
          rules: [
            { required: true, message: '请上传轮播图片!'},
          ]},
        carouselType:{
          rules: [
            { required: true, message: '请选择类型'},
          ]},
      },
      url: {
        add: "/cnCarouselController/saveOrUpdateEntity",
        edit: "/cnCarouselController/saveOrUpdateEntity",
        orderCustomerList: "/test/order/listOrderCustomerByMainId",
        orderTicketList: "/test/order/listOrderTicketByMainId",
      },
    }
  },
  methods: {
    add() {
      this.edit({});
    },
    edit(record) {
      this.form.resetFields();
      this.orderMainModel = Object.assign({}, record);
      this.visible = true;
      this.$nextTick(() => {
        this.form.setFieldsValue(Object.assign({},this.orderMainModel))
        this.form.setFieldsValue({orderDate: this.orderMainModel.orderDate ? moment(this.orderMainModel.orderDate) : null}) //时间格式化
      });
      console.log(this.orderMainModel)
    },
    close() {
      this.$emit('close');
      this.visible = false;
    },
    handleOk() {
      const that = this;
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          httpurl += this.url.add;
          method = 'post';
          let orderMainData = Object.assign(this.orderMainModel, values);
          //时间格式化
          orderMainData.orderDate = orderMainData.orderDate ? orderMainData.orderDate.format('YYYY-MM-DD HH:mm:ss') : null;
          let formData = {
            ...orderMainData
          }
          console.log(formData)
          httpAction(httpurl, formData, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.close();
          })
        }
      })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>

<style scoped>
.ant-btn {
  padding: 0 10px;
  margin-left: 3px;
}

.ant-form-item-control {
  line-height: 0px;
}

/** 主表单行间距 */
.ant-form .ant-form-item {
  margin-bottom: 10px;
}

/** Tab页面行间距 */
.ant-tabs-content .ant-form-item {
  margin-bottom: 0px;
}
</style>

